package com.addbrick.websocket.topic;

import com.alibaba.fastjson.JSON;
import com.addbrick.websocket.pojo.vo.SendMsgVO;
import com.addbrick.websocket.server.OpenWebSocketApi;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 订阅者
 * @author shiliuyinzhen
 */
@Component
public class WebsocketMsgListener implements MessageListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String messageStr = new String(message.getBody());
        SendMsgVO sendMsgVO = JSON.parseObject(messageStr, SendMsgVO.class);
        // 发送消息
        OpenWebSocketApi.send(sendMsgVO);
    }
}

